using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using IWMAG.Helpers;
using IWMAG.Core.Messaging;
using IWMAG.Scripting.Interpreter;

namespace IWMAG.Core.Objects {
    public class Level : IndexList<GameObject> {
        public Messenger Messages;
        public List<IHitbox> Solids = new List<IHitbox>();
        public CollisionHandlerObject Collisions;
        public ScriptEngine Script;

        public Level(ScriptEngine s) {
            Script = s;
            Messages = new Messenger(this);

            int index = Count;
            Collisions = new CollisionHandlerObject();
            Collisions.Load(index, this);
        }

        public override int Add(GameObject obj) {
            int index = base.Add(obj);
            obj.Load(index, this);
            return index;
        }

        public void Draw(float duration, SpriteBatch batch) {
            foreach (GameObject obj in this) {
                if (obj is DrawableGameObject) {
                    (obj as DrawableGameObject).Draw(duration, batch);
                }
            }
        }

        public void Update(float duration) {
            int i = 0;
            while (i < Data.Count) {
                if (Data[i].Item1 == true && Data[i].Item2.Enabled)
                    Data[i].Item2.Update(duration);
                i++;
            }
        }
    }
}
